package com.example.design.core;

import java.util.*;

/**
 * 任务上下文：收集错误信息、附加数据
 */
public class FileProcessingContext<T extends Enum<T> & SyncFieldDefinition> {

    private final List<Map<String, Object>> errorBuffer = new ArrayList<>();

    public void addFileError(String fileName, String message) {
        Map<String, Object> map = new HashMap<>();
        map.put("file", fileName);
        map.put("msg", message);
        errorBuffer.add(map);
    }

    public void addSystemError(String fileName, String message, Exception e) {
        Map<String, Object> map = new HashMap<>();
        map.put("file", fileName);
        map.put("msg", message);
        map.put("ex", e == null ? null : e.getMessage());
        errorBuffer.add(map);
    }

    public boolean hasErrors() { return !errorBuffer.isEmpty(); }

    public List<Map<String, Object>> getErrorBuffer() { return Collections.unmodifiableList(errorBuffer); }
}
